package com.Rest2Go;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.LinearLayout;

class MoveEatPagerAdapter extends BaseAdapter {

	Context mContext;
	int mCount;
	private Gallery mGallery;
	private ArrayList<MenuHandler> mList;
	private View mRestView;

	public MoveEatPagerAdapter(Context context, int count, Gallery gallery,
			ArrayList<MenuHandler> list, View restView) {
		mContext = context;
		mCount = count;
		mGallery = gallery;
		mList = list;
		mRestView = restView;
	}

	@Override
	public int getCount() {
		return mCount + 1;
	}

	@Override
	public Object getItem(int pos) {

		if (pos >= 1) {
//			mGallery.setSelection(pos - 1);
			View v = mList.get(pos).getView();
			return v;
		} else {
			return mRestView;
		}
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		mGallery.setAnimationDuration(500);
		mGallery.setSelection(position+1,true);
//		mGallery.onFling(null, null, 1, 0);
		if (convertView == null) {
			view = new View(mContext);
			view.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.FILL_PARENT,
					Gallery.LayoutParams.WRAP_CONTENT));
			if (position >= 1) {
				mGallery.setSelection(position - 1);
				view = mList.get(position-1).getView();
				
			} else {
//				view.removeView(mRestView);
				view=mRestView;
			}
		} else {
			view = (LinearLayout) convertView;
		}
		return view;
	}

}
